//
//  AdviceViewController.swift
//  DriverSchoolAPP
//
//  Created by Logel on 2017/5/25.
//  Copyright © 2017年 Logel. All rights reserved.
//

import UIKit

class AdviceViewController: UIViewController,LgCallBack,UITextFieldDelegate {
    @IBOutlet weak var content: UITextView!
    @IBOutlet weak var phoneLbl: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func doPost(_ sender: UIButton) {
        if content.text != "" {
             asyn_req_post(method: M_Advice, cb: self, p: ["accountId" : user.accountId as AnyObject,"content":"\(content.text)" as AnyObject,"channel":"iOS" as AnyObject,"contact":"\(phoneLbl.text)" as AnyObject])
        }else{
            showMsg(msg: "意见必须填写")
        }
       
    }
    
    func callBack(method: String, data: AnyObject) {
        let j = JSON(data)
        print(j)
        let head = parseMobileHead(x: j["MobileHead"])
        if head.code == "1" {
            showMsg(msg: "感谢您的反馈！我们会尽快处理。")
            content.text = ""
            phoneLbl.text = ""
        }else{
            showMsg(msg: head.message)
        }
    }
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        phoneLbl.resignFirstResponder()
    }
}
